package com.lej.core.binding.viewadapter.image

import android.graphics.drawable.Drawable
import android.widget.ImageView
import androidx.databinding.BindingAdapter
import com.bumptech.glide.Glide
import com.lej.core.utils.extention.safe

@BindingAdapter(value = ["url", "placeholder"], requireAll = true)
fun ImageView.setImage(url: String?, placeholder: Drawable) {
    Glide.with(context)
        .load(url.safe())
        .placeholder(placeholder)
        .error(placeholder)
        .into(this)
}

@BindingAdapter(value = ["src"])
fun ImageView.setDrawable(src: Drawable) {
    Glide.with(context)
        .load(src)
        .into(this)
}